home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 January, February, March & April
/
Chip-Cover-CD-2007-02.iso
/
Pakiet bezpieczenstwa
/
mini Pentoo LiveCD 2006.1
/
mpentoo-2006.1.iso
/
livecd.squashfs
/
usr
/
bin
/
localepurge
< prev
next >
Wrap
Text File
|
2006-01-09
|
7KB
|
236 lines
#!/bin/sh
# Deleting all locale files on system
# *not* listed in /etc/locale.nopurge
LOCALEDIRS="/usr/share/locale /usr/local/share/locale /usr/kde/?.?/share/locale /opt/sun-jdk-*/jre/lib/locale /opt/sun-jre-bin-*/lib/locale /usr/lib/locale"
MANPAGEDIRS="/usr/share/man /usr/man /usr/local/share/man /usr/kde/?.?/share/man /usr/kde/?.?/man /opt/sun-jdk-*/man /opt/sun-jre-bin-*/man"
LOCALELIST="/var/cache/localepurge/localelist"
VERSION="0.5"
LOCALETOTAL=0
MANTOTAL=0
set -e
if [ "$1" = "-debug" ] || [ "$1" = "-d" ] \
|| [ "$2" = "-debug" ] || [ "$2" = "-d" ] \
|| [ "$3" = "-debug" ] || [ "$3" = "-d" ] \
|| [ "$4" = "-debug" ] || [ "$4" = "-d" ] \
|| [ "$5" = "-debug" ] || [ "$5" = "-d" ]; then
set -x
fi
if [ "`grep -x ^NOCOLOR /etc/locale.nopurge`" ] \
|| [ "$1" = "-nocolor" ] || [ "$1" = "-nc" ] \
|| [ "$2" = "-nocolor" ] || [ "$2" = "-nc" ] \
|| [ "$3" = "-nocolor" ] || [ "$3" = "-nc" ] \
|| [ "$4" = "-nocolor" ] || [ "$4" = "-nc" ] \
|| [ "$5" = "-nocolor" ] || [ "$5" = "-nc" ]; then
NOCOLOR=yes
fi
if [[ ${NOCOLOR} == yes ]]; then
unset GOOD WARN BAD NORMAL HILITE BRACKET BOLD
else
GOOD=$'\e[32;01m'
WARN=$'\e[33;01m'
BAD=$'\e[31;01m'
NORMAL=$'\e[0m'
HILITE=$'\e[36;01m'
BRACKET=$'\e[34;01m'
BOLD=$'\e[1m'
fi
eerror () {
echo -e " ${BAD}*${NORMAL} $*"
}
ewarn () {
echo -e " ${WARN}*${NORMAL} $*"
}
einfo () {
echo -e " ${GOOD}*${NORMAL} $*"
}
etab () {
echo -e " ${GOOD}*${NORMAL} $*"
}
ayuda () {
echo "${HILITE}localepurge${NORMAL} for ${BOLD}Gentoo Linux${NORMAL} ${BRACKET}[${NORMAL} ${GOOD}${VERSION}${NORMAL} ${BRACKET}]${NORMAL}"
echo -e " " "by bass@gentoo.org"
echo
einfo "Remember that you must edit /etc/locale.nopurge"
echo
einfo "Usage: `basename $0` [options]"
echo
etab "${BOLD}-help (-h) ${NORMAL} : show this help."
etab "${BOLD}-debug (-d) ${NORMAL} : debug mode."
etab "${BOLD}-verbose (-v) ${NORMAL} : verbose mode."
etab "${BOLD}-nocolor (-nc) ${NORMAL} : no color mode."
etab "${BOLD}-version ${NORMAL} : show version."
echo
}
version () {
einfo "${BRACKET}[${NORMAL} ${GOOD}${VERSION}${NORMAL} ${BRACKET}]${NORMAL}"
}
if [ "$1" = "-help" ] || [ "$1" = "-h" ] \
|| [ "$2" = "-help" ] || [ "$2" = "-h" ] \
|| [ "$3" = "-help" ] || [ "$3" = "-h" ] \
|| [ "$4" = "-help" ] || [ "$4" = "-h" ] \
|| [ "$5" = "-help" ] || [ "$5" = "-h" ]; then
ayuda
exit 0
fi
if [ "$1" = "-version" ] \
|| [ "$2" = "-version" ] \
|| [ "$3" = "-version" ] \
|| [ "$4" = "-version" ] \
|| [ "$5" = "-version" ] ; then
version
exit 0
fi
if [ "`grep -x ^SHOWFREEDSPACE /etc/locale.nopurge`" ]; then
SHOWFREEDSPACE=enabled
fi
if [ "`grep -x ^VERBOSE /etc/locale.nopurge`" ] \
|| [ "$1" = "-verbose" ] || [ "$1" = "-v" ] \
|| [ "$2" = "-verbose" ] || [ "$2" = "-v" ] \
|| [ "$3" = "-verbose" ] || [ "$3" = "-v" ] \
|| [ "$4" = "-verbose" ] || [ "$4" = "-v" ] \
|| [ "$5" = "-verbose" ] || [ "$5" = "-v" ]; then
VERBOSE=enabled
fi
# Do nothing and report why if no valid configuration file exists:
if [ ! -f /etc/locale.nopurge ]
then
eerror " No /etc/locale.nopurge file present, exiting ..."
exit 0
else
if [ "`grep -x ^NEEDSCONFIGFIRST /etc/locale.nopurge`" ]
then
echo ""
einfo " You have to configure \"/etc/locale.nopurge\" "
echo ""
einfo " to make $0 actually start to function."
echo ""
einfo " Nothing to be done, exiting ..."
echo ""
exit 0
fi
fi
# Getting rid of superfluous locale files in $LOCALEDIR:
purgelocale () {
local LOCALEDIR="$1"
if [ -d $LOCALEDIR ]; then
if [ "$SHOWFREEDSPACE" = "enabled" ]; then
LOCALEBEFORE=$(df -P $LOCALEDIR | awk '{if ( NR==2 ) { print $3 }}')
fi
if [ "$VERBOSE" = "enabled" ]; then
einfo "localepurge: processing locale files in ${LOCALEDIR} ..."
for LOCALE in `/bin/ls ${LOCALEDIR}`
do
if [ ! "`grep -x ^${LOCALE} /etc/locale.nopurge`" ] && \
[ "`grep -x ^${LOCALE} ${LOCALELIST}`" ]; then
if [ -d ${LOCALEDIR}/${LOCALE}/LC_MESSAGES ]; then
/bin/rm -vf `find ${LOCALEDIR}/${LOCALE} -type f`
fi
fi
done
else
for LOCALE in `/bin/ls ${LOCALEDIR}`
do
if [ ! "`grep -x ^${LOCALE} /etc/locale.nopurge`" ] && \
[ "`grep -x ^${LOCALE} ${LOCALELIST}`" ]; then
if [ -d ${LOCALEDIR}/${LOCALE}/LC_MESSAGES ]; then
/bin/rm -f `find ${LOCALEDIR}/${LOCALE} -type f`
fi
fi
done
fi
if [ "$SHOWFREEDSPACE" = "enabled" ]; then
LOCALEAFTER=$(df -P $LOCALEDIR | awk '{if ( NR==2 ) { print $3 }}')
LOCALESUM=$(($LOCALEBEFORE - $LOCALEAFTER))
LOCALETOTAL=$(($LOCALETOTAL + $LOCALESUM))
if [ ! $LOCALEBEFORE = $LOCALEAFTER ]; then
einfo "localepurge: Disk space freed in $LOCALEDIR: ${BOLD}"$LOCALESUM"K${NORMAL}"
fi
fi
fi
}
# Getting rid of localized man pages in $MANPAGEDIR
purgeman () {
local MANPAGEDIR="$1"
if [ -d $MANPAGEDIR ] && [ "`grep -x ^MANDELETE /etc/locale.nopurge`" ]; then
if [ "$SHOWFREEDSPACE" = "enabled" ]; then
MANBEFORE=$(df -P $MANPAGEDIR | awk '{if ( NR==2 ) { print $3 }}')
fi
if [ "$VERBOSE" = "enabled" ]; then
einfo "localepurge: processing man pages in ${MANPAGEDIR} ..."
for LOCALE in `/bin/ls ${MANPAGEDIR} | grep -v ^man[1-9]`
do
if [ ! "`grep -x ^${LOCALE} /etc/locale.nopurge`" ] && \
[ "`grep -x ^${LOCALE} ${LOCALELIST}`" ]; then
if [ -d ${MANPAGEDIR}/${LOCALE} ]; then
/bin/rm -vf `find ${MANPAGEDIR}/${LOCALE} -type f`
fi
fi
done
else
for LOCALE in `/bin/ls ${MANPAGEDIR} | grep -v ^man[1-9]`
do
if [ ! "`grep -x ^${LOCALE} /etc/locale.nopurge`" ] && \
[ "`grep -x ^${LOCALE} ${LOCALELIST}`" ]; then
if [ -d ${MANPAGEDIR}/${LOCALE} ]; then
/bin/rm -f `find ${MANPAGEDIR}/${LOCALE} -type f`
fi
fi
done
fi
if [ "$SHOWFREEDSPACE" = "enabled" ]; then
MANAFTER=$(df -P $MANPAGEDIR | awk '{if ( NR==2 ) { print $3 }}')
MANSUM=$(($MANBEFORE - $MANAFTER))
MANTOTAL=$(($MANTOTAL + $MANSUM))
if [ ! $MANBEFORE = $MANAFTER ]; then
einfo "localepurge: Disk space freed in $MANPAGEDIR: ${BOLD}"$MANSUM"K${NORMAL}"
fi
fi
fi
}
for folder in ${LOCALEDIRS}; do
purgelocale "$folder"
done
for folder in ${MANPAGEDIRS}; do
purgeman "$folder"
done
# Calculating and reporting total disk space freed:
if [ "$SHOWFREEDSPACE" = "enabled" ]; then
if [ $MANTOTAL ] && [ $LOCALETOTAL ]; then
if [ ! $MANBEFORE = $MANAFTER ] && [ ! $LOCALEBEFORE = $LOCALEAFTER ]; then
echo ""
einfo "Total disk space freed by localepurge: ${BOLD}"$(($LOCALETOTAL + $MANTOTAL))"K${NORMAL}"
echo ""
fi
fi
fi